<template>
  <div id="regulationorder">
    <div  style="display:flex;align-items: center;">
          <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
          <div style="line-height: 40px;font-weight:bold;">领奖订单</div>
    </div>
    <el-form ref="form" :model="form" label-width="70px">

      <div style="display:flex;">
          <div style="flex:1;display:flex;align-items: center;">
             <div style="width:50px;text-align-last: justify;margin-top:-12px;font-size: 14px;color: #606266;margin-right:10px;">查询项</div>


            <el-form-item label="订单编号" >
               <el-input v-model="form.pid" placeholder="订单编号"  style="width:140px;"></el-input>
            </el-form-item>

            <el-form-item label="账户查询" style="margin-left:10px;">
               <el-input v-model="form.phone" placeholder="账户"  style="width:140px;"></el-input>
            </el-form-item>

            <div class="buttoon_box">
                <div class="buttoon_box_item cursor-po"  style="margin-left:10px;background:#FFC600;color:white;" @click="search_but1()">确 定</div>
                <div class="buttoon_box_item cursor-po" style="margin-left:10px;border:1px solid #D9D9D9;" @click="refresh_but()">清 空</div>
            </div>
         </div>
         <!-- <div>
              <el-button class="custom_color_button" type="primary" @click="but1()">类别设置</el-button>
         </div> -->
      </div>

      <div style="display:flex;align-items: center;">
            <div style="width:50px;text-align-last: justify;margin-top:-12px;font-size: 14px;color: #606266;margin-right:10px;">筛选项</div>

             <el-form-item label="订单日期">
                    <el-date-picker  type="date"   placeholder="选择订单日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="form.startDay" style="width:140px;">
                    </el-date-picker>
              </el-form-item>

            <el-form-item  label="发放奖品" style="margin-left:10px;">
                <el-select  v-model="form.deliver" placeholder="选择发放状态" style="width:140px;">
                    <el-option  v-for="(item,index) in select_status" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

             <el-form-item  label="发放蜂钻" style="margin-left:10px;">
                <el-select  v-model="form.status" placeholder="选择发放状态" style="width:140px;">
                    <el-option  v-for="(item,index) in select_status" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

            <div class="buttoon_box">
                <div class="buttoon_box_item cursor-po"  style="margin-left:10px;background:#FFC600;color:white;" @click="search_but2()">确 定</div>
                <div class="buttoon_box_item cursor-po" style="margin-left:10px;border:1px solid #D9D9D9;" @click="refresh_but()">清 空</div>
            </div>

      </div>



   </el-form>
   <!-- 渲染数据list -->
   <award-order-list :datalist="datalist" @handleSend="handleSend" @handleBee="handleBee" @up_list_fun="list_fun"> </award-order-list>


   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>

    <!-- 发货 -->
    <el-dialog title="发货" :visible.sync="send_popup"  width="600px">
      <div style="width:100%;">

        <div class="title_box" style="margin-top:-30px;">
          <div class="dian"></div>
          <div class="title_name">收货信息</div>
        </div>
        <div class="box_top">
          <div class="box_top_con">
            <div class="box_top_name" style="display:flex;">
              <div class="title_span1">收 货 人:</div>
              <div class="title_span2">
                <span  v-if="user_address.username">{{ user_address.username }}</span>
                <span v-else>-</span>
              </div>
            </div>
            <div class="box_top_name" style="display:flex;">
              <div class="title_span1">手 机 号:</div>
              <div class="title_span2">
                <span  v-if="user_address.telphone">{{ user_address.telphone }}</span>
                <span v-else>-</span>
              </div>
            </div>
            <div class="box_top_name" style="display:flex;">
              <div class="title_span1">收货地址:</div>
              <div class="title_span2">
                <span  v-if="user_address.region">{{ user_address.region }} {{ select_row.detail }}</span>
                <span v-else>-</span>
              </div>
            </div>
          </div>
        </div>

        <el-form ref="addressForm" :model="address_info" :rules="rules"
                 hide-required-asterisk
                 inline-message
                 label-width="80px" style="width:100%;">
          <div class="title_box" style="margin-top:20px;">
            <div class="dian"></div>
            <div class="title_name">商品信息</div>
          </div>

          <div class="box_top_con" style="margin-bottom:20px;">
            <el-form-item label="商品名称" prop="product_name">
              <el-input v-model="address_info.product_name" placeholder="商品名称"  style="width:200px;"></el-input>
            </el-form-item>
            <el-form-item label="商品规格"  prop="product_spec">
              <el-input v-model="address_info.product_spec" placeholder="商品规格"  style="width:200px;"></el-input>
            </el-form-item>
            <el-form-item label="商品价格"  prop="product_price">
              <el-input v-model="address_info.product_price" placeholder="商品价格"  style="width:200px;"></el-input>
            </el-form-item>
            <el-form-item label="商品数量"  prop="product_number">
              <el-input v-model="address_info.product_number" placeholder="商品数量"  style="width:200px;"></el-input>
            </el-form-item>
          </div>
          <div class="title_box" style="margin-top:20px;">
            <div class="dian"></div>
            <div class="title_name">物流信息</div>
          </div>
          <div style="margin-top:20px;">
            <el-form-item label="快递公司"  prop="express_name">
              <el-input v-model="address_info.express_name" placeholder="快递公司"  style="width:200px;"></el-input>
            </el-form-item>
            <el-form-item label="快递单号"  prop="express_number">
              <el-input v-model="address_info.express_number" placeholder="快递单号"  style="width:200px;"></el-input>
            </el-form-item>
            <div style="text-align: center;width:50%;margin:auto;margin-top:10px;">
              <el-button type="primary" class="custom_color_button" style="width:80%;" @click="handleConfirm">确认</el-button>
            </div>
          </div>
        </el-form>
      </div>
    </el-dialog>

    <!-- 匹配次数 -->
    <el-dialog title="发放蜂钻" :visible.sync="bee_popup"  width="300px" :close-on-click-modal="false">
      <div style="width:100%;">
        <el-input  v-model.trim="bee_price" placeholder="请输入蜂钻数量"></el-input>
        <div style="text-align: center;width:50%;margin: 30px auto 0;">
          <el-button type="primary" class="custom_color_button" style="width:80%;" @click="handleConfirmBee()">确认</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import AwardOrderList from '@/view/Exchangeorder/awardOrderList'
export default {
  name: 'regulationorder',
  data () {
    return {
      datalist:[],
      page:1,
      select_index: -1,
      select_row: {},
      count:0,
      send_popup: false,
      bee_popup: false,
      form:{
        phone:'',
        pid:'',
        startDay:'',
        status: -1,
        deliver: -1
      },
      select_status:[{"id":-1,"name":"查全部"},{"id":0,"name":"未处理"},{"id":1,"name":"已处理"}],
      user_address: {},
      address_info: {
        express_number: '',
        express_name: '',
        product_name: '',
        product_spec: '',
        product_price: '',
        product_number: ''
      },
      rules: {
        product_name: [
          { required: true, message: '请填写商品名称', trigger: 'blur' }
        ],
        product_spec: [
          { required: true, message: '请填写商品规格', trigger: 'blur' }
        ],
        product_price: [
          { required: true, message: '请填写商品价格', trigger: 'blur' }
        ],
        product_number: [
          { required: true, message: '请填写商品数量', trigger: 'blur' }
        ],
        express_name: [
          { required: true, message: '请填写快递公司', trigger: 'blur' }
        ],
        express_number: [
          { required: true, message: '请填写快递单号', trigger: 'blur' }
        ],
      },
      bee_price: 0,
    }
  },
 components:{
   AwardOrderList
  },
  created(){
     this.list_fun()

  },
  mounted (){

  },
  methods: {
    /**
     * 获取列表
     */
     list_fun(){
        this.post("win_price/applyList", {
            page:this.page,
            pid:this.form.pid,
            telphone:this.form.phone,
            startday:this.form.startDay,
            status:this.form.status,
            deliver:this.form.deliver
        }).then(res => {
          const { count, list } = res.result
          this.count = count
          this.datalist = list
       })
    },
    /**
     * 获取地址
     */
    getAddress() {
      this.post("win_price/address", {
        id: this.select_row.id
      }).then(res => {
        console.log(res)
        this.user_address = res.result
        this.send_popup = true
      })
    },
    search_but1(){
      this.page = 1
      this.list_fun()
    },
    search_but2(){
      this.page = 1
      this.list_fun()
    },
    refresh_but(){
      this.page = 1
      this.form={
        phone:'',
        pid:'',
        startDay:'',
        status: -1,
        deliver: -1
      }
      this.list_fun()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.page = val
      this.list_fun()
      console.log(`当前页: ${val}`);
    },
    /**
     * 打开发货弹窗
     * @param scope
     */
    handleSend(scope) {
      this.select_index = scope.$index
      this.select_row = scope.row
      this.getAddress()
    },
    /**
     * 打开蜂钻弹窗
     * @param scope
     */
    handleBee(scope) {
      this.select_index = scope.$index
      this.select_row = scope.row
      this.bee_popup = true
    },
    /**
     * 确认发货
     */
    handleConfirm() {
      this.$refs.addressForm.validate((valid) => {
        if (valid) {
          this.address_info.id = this.select_row.id
          this.post("win_price/sureDeliver", this.address_info).then(res => {
            this.$message.success({ message: res.result, center: true })
            this.$set(this.datalist[this.select_index],'deliver',1)
            this.send_popup = false
            this.select_index = -1
            this.select_row = {}
            this.address_info = {
                express_number: '',
                express_name: '',
                product_name: '',
                product_spec: '',
                product_price: '',
                product_number: ''
            }
          })
        } else {
          return false;
        }
      })
    },
    /**
     * 确认蜂钻
     */
    handleConfirmBee() {
      const inspect = new RegExp('^(-?\\d+)(\\.\\d+)?$')
      if(!inspect.test(this.bee_price)) return this.$message.warning({message: '请输入数字', center: true})
      this.post("win_price/giveDob", {
        id: this.select_row.id,
        dob_number: this.bee_price
      }).then(res => {
        this.$message.success({ message: res.result, center: true })
        this.$set(this.datalist[this.select_index],'status',1)
        this.bee_popup = false
        this.select_index = -1
        this.select_row = {}
        this.bee_price = 0
      })
    }
  }
}
</script>


<style scoped>
  .cursor-po {
    cursor: pointer;
  }
  .buttoon_box{
    display:flex;margin-bottom:10px;
  }
  .buttoon_box_item{
    height:40px;line-height:40px;width:60px;font-size:14px;text-align:center;border-radius:5px;
  }
  .el-input-box>>>input{
    padding: 0px 3px !important;
  }
  .title_box{
    display: flex;
    align-items: center;
    margin-top: 8px;
  }
  .dian{
    width: 8px;
    height: 8px;
    background: #F1C94A;
    border-radius:50%;
    margin-right: 8px;
  }
  .title_name{
    font-size: 14px;;
    font-weight: 400;
    color: #000000;
  }
  .box_top{
    display: flex;
    margin-top:10px;
  }
  .box_top_con{
    margin-left:10px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }
  .box_top_name{
    margin-top:10px;
  }
  .title_span1{
    width: 85px;
    text-align-last: justify;
    color:#5E6C84;
    font-size:16px;
  }
  .title_span2{
    color:#888888;
    padding-left: 10px;
    padding-top:2px;
  }
</style>
